
import * as cc from 'cc';
import BaseComponent from '../../../../../framework/components/BaseComponent';
import { GuideData } from '../../define/GuideData';
import { IGuideTips } from '../../define/IGuideTips';
const { ccclass, menu, property } = cc._decorator;
@ccclass
@menu('Guide/ComGuideTips')
/**引导样式逻辑组件,不同项目不同逻辑 */
export default class ComGuideTips extends BaseComponent implements IGuideTips {


    @property({ type: cc.Label, tooltip: "提示语" })
    txtTips: cc.Label = null;
    @property({ type: cc.Label, tooltip: "下一步" })
    txtNext: cc.Label = null;

    @property({ type: cc.Node, tooltip: "下一步按钮" })
    btnNext: cc.Node = null;

    private clickNextCallback: () => void;
    start() {
        this.setClickListener(this.btnNext, this.onClick, this);
    }

    init() {
    }

    showTips(isShow: boolean, data?: GuideData, worldPos?: cc.Vec3, callback?: () => void) {

        this.unscheduleAllCallbacks();
        if (!isShow || !data) {
            this.node.active = false;
            return;
        }
        this.clickNextCallback = callback;
        if (data.tips) {
            this.txtTips.string = data.tips;
            this.txtTips.node.active = true;
        } else {
            this.txtTips.node.active = false;
        }
        this.node.active = isShow;
        // if (worldPos) {
        //     this.node.y = this.node.parent.convertToNodeSpaceAR(worldPos).y;
        // }
        if (data.strNext) {
            this.btnNext.active = true;
            this.txtNext.string = data.strNext;

            this.scheduleOnce(() => {
                // GuideMgr.getInstance().guide.showHand(true, data.handScale)
                // let nodePos = GuideMgr.getInstance().guide.guideHand.parent.getComponent(UITransform).convertToNodeSpaceAR(this.btnNext.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO))
                // tween(GuideMgr.getInstance().guide.guideHand)
                //     .to(GuideMgr.getInstance().guide.handMoveTime, { position: v3(nodePos.x, nodePos.y, nodePos.z) })
                //     .start()
            }, 3);

        } else {
            this.btnNext.active = false;
        }
        this.scheduleOnce(() => {
            // this.node.setPosition(this.node.position.x, this.node.position.y + data.tips_offse_y || 0, this.node.position.z)
        })
    }

    onClick() {
        this.clickNextCallback && this.clickNextCallback();
        this.clickNextCallback = null;
        this.unscheduleAllCallbacks();
    }



}